/**
  * <br>JAVACC DEMO 1.0<br>
*/
package com.apache.portal.weixin.core.manager;

import java.util.HashMap;
import java.util.Map;

import com.apache.portal.weixin.core.common.CoreService;
import com.apache.portal.weixin.core.manager.impl.parser.WxRecvEventMsgParser;
import com.apache.portal.weixin.core.manager.impl.parser.WxRecvGeoMsgParser;
import com.apache.portal.weixin.core.manager.impl.parser.WxRecvLinkMsgParser;
import com.apache.portal.weixin.core.manager.impl.parser.WxRecvPicMsgParser;
import com.apache.portal.weixin.core.manager.impl.parser.WxRecvTextMsgParser;
import com.apache.portal.weixin.core.manager.impl.parser.WxRecvVideoMsgParser;
import com.apache.portal.weixin.core.manager.impl.parser.WxRecvVoiceMsgParser;
import com.apache.portal.weixin.core.manager.impl.send.EventMsgManagerImpl;
import com.apache.portal.weixin.core.manager.impl.send.OrtherMsgManagerImpl;
import com.apache.portal.weixin.core.manager.impl.send.PicMsgManagerImpl;
import com.apache.portal.weixin.core.manager.impl.send.TextMsgManagerImpl;

/**
  * description: manager工厂类
  * @author Hou DaYu 创建时间：上午09:34:48
  */
public class BeanFactory {

	private static BeanFactory instance;

	private static Map<String, ResMsgManager> beans = new HashMap<String, ResMsgManager>();
	private static Map<String, WxRecvMsgParser> recvParserMap = new HashMap<String, WxRecvMsgParser>();

	private CoreService coreService;

	private BeanFactory() {
		// 文本消息解析程序
		recvParserMap.put("text", new WxRecvTextMsgParser());
		// 链接消息解析程序
		recvParserMap.put("link", new WxRecvLinkMsgParser());
		// 地址消息解析程序
		recvParserMap.put("location", new WxRecvGeoMsgParser());
		// 图片消息解析程序
		recvParserMap.put("image", new WxRecvPicMsgParser());
		// 事件消息解析程序
		recvParserMap.put("event", new WxRecvEventMsgParser());
		// 语音消息
		recvParserMap.put("voice", new WxRecvVoiceMsgParser());
		//视频消息
		recvParserMap.put("video", new WxRecvVideoMsgParser());
		//语音消息
		recvParserMap.put("music", new WxRecvVoiceMsgParser());

		//以下为manager注入
		beans.put("text", new TextMsgManagerImpl());
		beans.put("pic", new PicMsgManagerImpl());
		beans.put("orther", new OrtherMsgManagerImpl());
		beans.put("event", new EventMsgManagerImpl());
	}

	public synchronized static BeanFactory getInstance() {
		if (null == instance) {
			instance = new BeanFactory();
		}
		return instance;
	}

	public ResMsgManager getBeans(String key) {
		return beans.get(key);
	}

	public void setBeans(ResMsgManager value, String key) {
		if (null == beans.get(key))
			beans.put(key, value);
	}

	public WxRecvMsgParser getBeansParser(String key) {
		return recvParserMap.get(key);
	}

	public void setBeansParser(WxRecvMsgParser value, String key) {
		if (null == recvParserMap.get(key))
			recvParserMap.put(key, value);
	}

	public CoreService getCoreService() {
		if (null == coreService)
			coreService = new CoreService();
		return coreService;
	}
}
